home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch01 / modetest.c < prev    next >
Text File  |  1993-12-06  |  6KB  |  210 lines

  1. /**
  2.  ** MODETEST.C
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **    modified by Grzegorz Mazur for VESA driver compatibility
  9.  **    gbm@ii.pw.edu.pl
  10.  **
  11.  **  This file is distributed under the terms listed in the document
  12.  **  "copying.cb", available from the author at the address above.
  13.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  14.  **  should be available from where this file was obtained.  This file
  15.  **  may not be distributed without a verbatim copy of "copying.cb".
  16.  **  You should also have received a copy of the GNU General Public
  17.  **  License along with this program (it is in the file "copying");
  18.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  19.  **  Cambridge, MA 02139, USA.
  20.  **
  21.  **  This program is distributed in the hope that it will be useful,
  22.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  23.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24.  **  GNU General Public License for more details.
  25.  **/
  26.  
  27. #include <grx/grx.h>
  28. #include <grx/mousex.h>
  29. #include <grx/grdriver.h>
  30. #include <string.h>
  31. #include <stdlib.h>
  32. #include <ctype.h>
  33. #include <dos.h>
  34.  
  35. #ifdef __TURBOC__
  36. #define ENV_VAR "GRXDRV"
  37. #endif
  38.  
  39. #ifdef __GNUC__
  40. #define ENV_VAR "GO32"
  41. #endif
  42.  
  43. GR_DRIVER_MODE_ENTRY far *ttab,*gtab;
  44. int txt_modes,gra_modes;
  45. int    number_of_colors;
  46.  
  47. void list_modes(void)
  48. {
  49.     char buf[20];
  50.     char tentry[100];
  51.     char gentry[100];
  52.     char *env = getenv(ENV_VAR);
  53.     int  mode;
  54.  
  55.     if(env != NULL)
  56.         printf("Value of environment variable \"%s\" is:\n\"%s\"\n\n",ENV_VAR,env);
  57.     printf("%-32s%s\n\n","Available text modes:","Available graphics modes:");
  58.     txt_modes = 0;
  59.     gra_modes = 0;
  60.     while((ttab[txt_modes].width != 0) || (gtab[gra_modes].width != 0)) {
  61.         tentry[0] = '\0';
  62.         gentry[0] = '\0';
  63.         if(ttab[txt_modes].width != 0) {
  64.         mode = ttab[txt_modes].BIOS_mode +
  65.             (ttab[txt_modes].special << 8);
  66.         sprintf(tentry,
  67.             "(t%d%s  %3dx%-2d C:%-2d %s",
  68.             txt_modes+1,
  69.             ((txt_modes < 9) ? ") " : ")"),
  70.             ttab[txt_modes].width,
  71.             ttab[txt_modes].height,
  72.             ttab[txt_modes].number_of_colors,
  73.             ((ttab[txt_modes].BIOS_mode == 0xff) ?
  74.             "Disabled" :
  75.             (sprintf(buf,"BIOS:%03xh",mode),buf)
  76.         ));
  77.         if(ttab[txt_modes].special & 0xf0) strcat(tentry," *");
  78.         txt_modes++;
  79.         }
  80.         if(gtab[gra_modes].width != 0) {
  81.         mode = gtab[gra_modes].BIOS_mode +
  82.             (gtab[gra_modes].special << 8);
  83.             number_of_colors = gtab[gra_modes].number_of_colors;
  84.             if (number_of_colors > 0xc000)
  85.                 number_of_colors = 1 << (number_of_colors & 0xff);
  86.         sprintf(gentry,
  87.             "(g%d%s  %4dx%-3d C:%-8u %s",
  88.             gra_modes+1,
  89.             ((gra_modes < 9) ? ") " : ")"),
  90.             gtab[gra_modes].width,
  91.             gtab[gra_modes].height,
  92.             number_of_colors,
  93.             ((gtab[gra_modes].BIOS_mode == 0xff) ?
  94.             "Disabled" :
  95.             (sprintf(buf,"BIOS:%03xh",mode),buf)
  96.         ));
  97.         if(gtab[gra_modes].special & 0xf0) strcat(gentry," *");
  98.         gra_modes++;
  99.         }
  100.         printf("%-32s%s\n",tentry,gentry);
  101.     }
  102.     printf("\nEnter mode to test or 'Q' to quit: ");
  103.     fflush(stdout);
  104. }
  105.  
  106. void test_textmode(int mode)
  107. {
  108.     int ii;
  109.  
  110.     if(mode < 0) return;
  111.     if(mode >= txt_modes) return;
  112.     if(ttab[mode].BIOS_mode == 0xff) return;
  113.     GrSetMode(GR_width_height_text,ttab[mode].width,ttab[mode].height);
  114.     do {
  115.         printf("\n\nThis is a text mode of width=%d by height=%d\n",
  116.         ttab[mode].width,
  117.         ttab[mode].height
  118.         );
  119.         for(ii = 4; ii < 512; ii += 4) printf("%4d",ii);
  120.         printf("\nPress any key to abort this test...");
  121.         fflush(stdout);
  122. #ifdef __TURBOC__
  123.         delay(2000);
  124. #endif
  125. #ifdef __GNUC__
  126.         sleep(2);
  127. #endif
  128.     } while(!kbhit());
  129.     getkey();
  130. }
  131.  
  132. #define XP(x)    (int)((((long)(x) * (long)xsize) / 100L) + xpos)
  133. #define YP(y)    (int)((((long)(y) * (long)ysize) / 100L) + ypos)
  134.  
  135. void drawing(int xpos,int ypos,int xsize,int ysize,int fg,int bg)
  136. {
  137.     int ii;
  138.  
  139.     if(bg != GrNOCOLOR) {
  140.         GrFilledBox(xpos,ypos,xpos+xsize-1,ypos+ysize-1,bg);
  141.     }
  142.     GrLine(XP(10),YP(10),XP(40),YP(40),fg);
  143.     GrLine(XP(40),YP(10),XP(10),YP(40),fg);
  144.     GrLine(XP(35),YP(10),XP(65),YP(40),fg);
  145.     GrLine(XP(35),YP(40),XP(65),YP(10),fg);
  146.     GrLine(XP(70),YP(10),XP(90),YP(40),fg);
  147.     GrLine(XP(70),YP(40),XP(90),YP(10),fg);
  148.     for(ii = 0; ii < 5; ii++) {
  149.         GrBox(XP(70+2*ii),YP(10+3*ii),XP(90-2*ii),YP(40-3*ii),fg);
  150.     }
  151.     GrFilledBox(XP(10),YP(50),XP(60),YP(90),fg);
  152.     GrBox(XP(70),YP(50),XP(90),YP(90),fg);
  153.     for(ii = 0; ii < 100; ii++) {
  154.         GrPlot(XP((random() % 20) + 70),YP((random() % 40) + 50),fg);
  155.     }
  156. }
  157.  
  158. void test_graphicsmode(int mode)
  159. {
  160.     char buf[100];
  161.  
  162.     if(mode < 0) return;
  163.     if(mode >= gra_modes) return;
  164.     if(gtab[mode].BIOS_mode == 0xff) return;
  165.     GrSetMode(GR_width_height_color_graphics,
  166.         gtab[mode].width,
  167.         gtab[mode].height,
  168.         gtab[mode].number_of_colors
  169.     );
  170.     sprintf(buf,
  171.         "%dx%d graphics with %d colors",
  172.         GrSizeX(),
  173.         GrSizeY(),
  174.         GrNumColors()
  175.     );
  176.     GrClearScreen(GrBlack());
  177.     drawing(0,0,GrSizeX(),GrSizeY()-35,GrWhite(),GrNOCOLOR);
  178.     GrTextXY(0,GrSizeY()-32,buf,GrWhite(),GrNOCOLOR);
  179.     GrTextXY(0,GrSizeY()-16,"Press any key to continue...",GrWhite(),GrNOCOLOR);
  180.     getkey();
  181. }
  182.  
  183. void main(void)
  184. {
  185.     char reply[80];
  186.  
  187.     GrSetMode(GR_80_25_text);
  188.     GrGetDriverModes(&ttab,>ab);
  189.     if(!ttab || !gtab) {
  190.         printf("MODETEST will work only with a new format driver\n");
  191.         exit(0);
  192.     }
  193.     for( ; ; ) {
  194.         GrSetMode(GR_80_25_text);
  195.         list_modes();
  196.         gets(reply);
  197.         switch(tolower(reply[0])) {
  198.           case 't':
  199.         test_textmode(atoi(&reply[1]) - 1);
  200.         break;
  201.           case 'g':
  202.         test_graphicsmode(atoi(&reply[1]) - 1);
  203.         break;
  204.           case 'q':
  205.         exit(0);
  206.         }
  207.     }
  208. }
  209.  
  210.